home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
mui
/
bcc_src.lha
/
Parser
/
Bug
/
MainWin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-01-16
|
17KB
|
615 lines
/*
This file was generated by BCC v2.0
MUI mode
*/
/* .bcc_code for MUI mode */
/* Defines that help adjusting to any compiler */
#ifdef _DCC
#define REG(x) __ ## x
#define ASM
#define SAVEDS __geta4
#else
#define REG(x) register __ ## x
#ifdef _STORM
#define ASM
#define SAVEDS __saveds
#else
#if defined __MAXON__ || defined __GNUC__
#define ASM
#define SAVEDS
#else
#define ASM __asm
#define SAVEDS __saveds
#endif
#endif
#endif
#ifndef PROTO_MUIMASTER_H
#include <proto/muimaster.h>
#endif
#ifndef PROTO_INTUITION_H
#include <proto/intuition.h>
#endif
#ifndef PROTO_UTILITY_H
#include <proto/utility.h>
#endif
#ifndef STRING_H
#include <string.h>
#endif
#ifndef LIBRARIES_BCC_H
#include <libraries/bcc.h>
#endif
#ifndef CLIB_ALIB_PROTOS_H
#include <clib/alib_protos.h>
#endif
/* Only for custom methods */
#define CallSuper() DoSuperMethodA(cl, obj, msg)
#define GetData() INST_DATA(cl, obj)
#include <math.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
#include <proto/asl.h>
#include <dos/dos.h>
#include <libraries/asl.h>
#include <intuition/intuition.h>
#include "global.h"
#include "model.h"
#include "load.h"
#include "App.h"
#include "Mainwin.h"
#include "View.h"
#define fract(n) (n - floor(n))
static __saveds __asm void IntuiMsgFunc(register __a1 struct IntuiMessage=
*,register __a2 struct FileRequester *);
static char *getfilename(Object *,char *,char *,char *,char);
static unsigned long mMainwinOM_NEW( struct IClass *cl, Object *obj, struct opSet* msg )
{
unsigned long _ret;
MainwinData *data, _tdata;
data = &_tdata;
memset( data, 0, sizeof( MainwinData ) );
obj = (Object*)BCC_DoSuperNew( cl, obj,
MUIA_Window_Title, "Geotto",
MUIA_Window_ID, MAKE_ID('M','A','I','N'),
MUIA_Window_NeedsMouseObject, TRUE,
/*
MUIA_Window_CloseGadget, FALSE,
MUIA_Window_DepthGadget, FALSE,
MUIA_Window_DragBar, FALSE,
MUIA_Window_Backdrop, TRUE,
MUIA_Window_Borderless, TRUE,
*/
WindowContents, VGroup,
Child, HGroup,
Child, VGroup,
MUIA_Weight, 0,
Child, SimpleButton("About"),
Child, (data->newobj) =3D KeyButton("New",'n'),
Child, TextObject,
MUIA_Text_Contents, "Fetch",
End,
Child, (data->loadobj) =3D KeyButton("Load",'l'),
Child, KeyButton("Save",'s'),
Child, KeyButton("Save As",'s'),
Child, TextObject,
MUIA_Text_Contents, "Zoom",
End,
Child, (data->zoomin) =3D KeyButton("In",'+'),
Child, (data->zoomout) =3D KeyButton("Out",'-'),
Child, HVSpace,
Child, VGroup,
TextFrame,
MUIA_Background, MUII_TextBack,
Child, (data->xcoordtxt) =3D TextObject, End,
Child, (data->ycoordtxt) =3D TextObject, End,
Child, (data->zcoordtxt) =3D TextObject, End,
End,
End,
Child, (data->viewgr) =3D ColGroup(2),
MUIA_Group_HorizSpacing, 1,
MUIA_Group_VertSpacing, 1,
Child, (data->view1) =3D ViewObject,
VirtualFrame,
MUIA_View_Mode, MUIV_View_Mode_Top,
MUIA_View_X, f2l(0.0),
MUIA_View_Y, f2l(0.0),
MUIA_View_Z, f2l(0.0),
MUIA_View_Zoom, f2l(0.1),
MUIA_View_GridSize, f2l(1.0),
End,
Child, (data->view2) =3D ViewObject,
VirtualFrame,
MUIA_View_Mode, MUIV_View_Mode_Persp,
MUIA_View_X, f2l(0.0),
MUIA_View_Y, f2l(0.0),
MUIA_View_Z, f2l(0.0),
MUIA_View_Zoom, f2l(0.1),
MUIA_View_GridSize, f2l(1.0),
End,
Child, (data->view3) =3D ViewObject,
VirtualFrame,
MUIA_View_Mode, MUIV_View_Mode_Face,
MUIA_View_X, f2l(0.0),
MUIA_View_Y, f2l(0.0),
MUIA_View_Z, f2l(0.0),
MUIA_View_Zoom, f2l(0.1),
MUIA_View_GridSize, f2l(1.0),
End,
Child, (data->view4) =3D ViewObject,
VirtualFrame,
MUIA_View_Mode, MUIV_View_Mode_Left,
MUIA_View_X, f2l(0.0),
MUIA_View_Y, f2l(0.0),
MUIA_View_Z, f2l(0.0),
MUIA_View_Zoom, f2l(0.1),
MUIA_View_GridSize, f2l(1.0),
End,
End,
End,
Child, HGroup,
Child, (data->gridsizetxt) =3D TextObject,
TextFrame,
MUIA_Background, MUII_TextBack,
MUIA_Text_Contents, "Grid:",
End,
Child, (data->poks) =3D SimpleButton("MUI Settings..."),
End,
End
,
TAG_MORE, (unsigned long)msg->ops_AttrList,
TAG_DONE );
_ret = (unsigned long)obj;
if( !obj ) return 0;
data = INST_DATA( cl, obj );
memcpy( data, &_tdata, sizeof( MainwinData ) );
{
/* UC Beg */
BCC_Set( obj, MUIA_Mainwin_Zoom, 3D 0.1 );
DoMethod( (data->poks), MUIM_Notify, MUIA_Pressed,FALSE,MUIV_Notify_Application,2,MUIM_Applicat=
ion_OpenConfigWindow,0);
DoMethod( (data->newobj), MUIM_Notify, MUIA_Pressed,FALSE,obj,1,MUIM_Mainwin_New);
DoMethod( (data->loadobj), MUIM_Notify, MUIA_Pressed,FALSE,obj,1,MUIM_Mainwin_Load);
DoMethod( (data->zoomin), MUIM_Notify, MUIA_Pressed,FALSE,obj,1,MUIM_Mainwin_ZoomIn);
DoMethod( (data->zoomout), MUIM_Notify, MUIA_Pressed,FALSE,obj,1,MUIM_Mainwin_ZoomOut);
(data->ehnode).ehn_Priority =3D 0;
(data->ehnode).ehn_Flags =3D 0;
(data->ehnode).ehn_Object =3D obj;
(data->ehnode).ehn_Class =3D NULL;
(data->ehnode).ehn_Events =3D IDCMP_RAWKEY | IDCMP_MOUSEMOVE;
DoMethod( obj, MUIM_Window_AddEventHandler, &(data->ehnode));
(data->objreq) =3D MUI_AllocAslRequestTags(ASL_FileRequest,
ASLFR_InitialDrawer, "3D:",
ASLFR_InitialPattern, "#?.(lwo|img)",
ASLFR_DoPatterns, TRUE,
ASLFR_RejectIcons, TRUE,
TAG_DONE);
(data->Model) =3D AllocModel();
/* {
vertex_t *v[8];
polygon_t *p;
v[0] =3D AddVertex(Model); v[0]->x =3D -1.0; v[0]->y =3D 1.0; v[0]->z =3D=
1.0;
v[1] =3D AddVertex(Model); v[1]->x =3D 1.0; v[1]->y =3D 1.0; v[1]->z =3D=
1.0;
v[2] =3D AddVertex(Model); v[2]->x =3D -1.0; v[2]->y =3D -1.0; v[2]->z =
=3D 1.0;
v[3] =3D AddVertex(Model); v[3]->x =3D 1.0; v[3]->y =3D -1.0; v[3]->z =3D=
1.0;
v[4] =3D AddVertex(Model); v[4]->x =3D -1.0; v[4]->y =3D 1.0; v[4]->z =3D=
-1.0;
v[5] =3D AddVertex(Model); v[5]->x =3D 1.0; v[5]->y =3D 1.0; v[5]->z =3D=
-1.0;
v[6] =3D AddVertex(Model); v[6]->x =3D -1.0; v[6]->y =3D -1.0; v[6]->z =
=3D -1.0;
v[7] =3D AddVertex(Model); v[7]->x =3D 1.0; v[7]->y =3D -1.0; v[7]->z =3D=
-1.0;
p =3D AddPolygon(Model); AddPolyvert(p,v[0]); AddPolyvert(p,v[1]); AddPo=
lyvert(p,v[3]); AddPolyvert(p,v[2]);
p =3D AddPolygon(Model); AddPolyvert(p,v[4]); AddPolyvert(p,v[5]); AddPo=
lyvert(p,v[7]); AddPolyvert(p,v[6]);
p =3D AddPolygon(Model); AddPolyvert(p,v[0]); AddPolyvert(p,v[1]); AddPo=
lyvert(p,v[5]); AddPolyvert(p,v[4]);
p =3D AddPolygon(Model); AddPolyvert(p,v[2]); AddPolyvert(p,v[3]); AddPo=
lyvert(p,v[7]); AddPolyvert(p,v[6]);
}
*/
//LoadModel("CC:Lambda/orig/freighter.lwo",Model);
//LoadModel("CC:Lambda/orig/mfighter2.img",Model);
BCC_Set( (data->viewgr), MUIA_View_Model, 3D (data->Model) );
}
/* UC End */
OM_NEW_exit:
return _ret;
}
static unsigned long mMainwinOM_DISPOSE( struct IClass *cl, Object *obj, Msg msg )
{
unsigned long _ret = 1;
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
DoMethod( obj, MUIM_Window_RemEventHandler, &(data->ehnode));
MUI_FreeAslRequest((data->objreq));
FreeModel((data->Model));
}
/* UC End */
OM_DISPOSE_exit:
_ret = DoSuperMethodA( cl, obj, (Msg)msg );
return _ret;
}
static unsigned long mMainwinMUIM_HandleEvent( struct IClass *cl, Object *obj, struct MUIP_HandleEvent* msg )
{
unsigned long _ret = 1;
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
Object *mouseobj =3D (Object *)BCC_XGet( obj, MUIA_Window_MouseObject );
if (msg->imsg)
{
if (mouseobj =3D=3D (data->view1))
{
switch(msg->imsg->Class)
{
case IDCMP_RAWKEY:
switch(msg->imsg->Code)
{
case 76:
DoMethod( (data->viewgr), MUIM_View_ScrollZPos);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 77:
DoMethod( (data->viewgr), MUIM_View_ScrollZNeg);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 79:
DoMethod( (data->viewgr), MUIM_View_ScrollXPos);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 78:
DoMethod( (data->viewgr), MUIM_View_ScrollXNeg);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
}
break;
case IDCMP_MOUSEMOVE:
BCC_Set( (data->xcoordtxt), MUIA_Text_Contents, 3D "X 0.0 m" );
BCC_Set( (data->ycoordtxt), MUIA_Text_Contents, 3D NULL );
BCC_Set( (data->zcoordtxt), MUIA_Text_Contents, 3D "Z 0.0 m" );
break;
}
}
else if (mouseobj =3D=3D (data->view3))
{
switch(msg->imsg->Class)
{
case IDCMP_RAWKEY:
switch(msg->imsg->Code)
{
case 76:
DoMethod( (data->viewgr), MUIM_View_ScrollYPos);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 77:
DoMethod( (data->viewgr), MUIM_View_ScrollYNeg);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 79:
DoMethod( (data->viewgr), MUIM_View_ScrollXPos);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 78:
DoMethod( (data->viewgr), MUIM_View_ScrollXNeg);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
}
break;
case IDCMP_MOUSEMOVE:
BCC_Set( (data->xcoordtxt), MUIA_Text_Contents, 3D "X 0.0 m" );
BCC_Set( (data->ycoordtxt), MUIA_Text_Contents, 3D "Y 0.0 m" );
BCC_Set( (data->zcoordtxt), MUIA_Text_Contents, 3D NULL );
break;
}
}
else if (mouseobj =3D=3D (data->view4))
{
switch(msg->imsg->Class)
{
case IDCMP_RAWKEY:
switch(msg->imsg->Code)
{
case 76:
DoMethod( (data->viewgr), MUIM_View_ScrollYPos);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 77:
DoMethod( (data->viewgr), MUIM_View_ScrollYNeg);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 79:
DoMethod( (data->viewgr), MUIM_View_ScrollZNeg);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
case 78:
DoMethod( (data->viewgr), MUIM_View_ScrollZPos);
{ _ret = MUI_EventHandlerRC_Eat; goto MUIM_HandleEvent_exit; }
break;
}
break;
case IDCMP_MOUSEMOVE:
BCC_Set( (data->xcoordtxt), MUIA_Text_Contents, 3D NULL );
BCC_Set( (data->ycoordtxt), MUIA_Text_Contents, 3D "Y 0.0 m" );
BCC_Set( (data->zcoordtxt), MUIA_Text_Contents, 3D "Z 0.0 m" );
break;
}
}
else
{
if (msg->imsg->Class =3D=3D IDCMP_MOUSEMOVE)
{
BCC_Set( (data->xcoordtxt), MUIA_Text_Contents, 3D NULL );
BCC_Set( (data->ycoordtxt), MUIA_Text_Contents, 3D NULL );
BCC_Set( (data->zcoordtxt), MUIA_Text_Contents, 3D NULL );
}
}
}
{ _ret = 0; goto MUIM_HandleEvent_exit; }
}
/* UC End */
MUIM_HandleEvent_exit:
return _ret;
}
static unsigned long mMainwinNew( struct IClass *cl, Object *obj, Msg msg )
{
unsigned long _ret = 1;
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
RemAllVertices((data->Model));
MUI_Redraw((data->viewgr),MADF_DRAWOBJECT);
}
/* UC End */
New_exit:
return _ret;
}
static __saveds __asm void IntuiMsgFunc(register __a1 struct IntuiMessage=
*imsg,register __a2 struct FileRequester *req)
{
if (imsg->Class =3D=3D IDCMP_REFRESHWINDOW)
DoMethod(req->fr_UserData,MUIM_Application_CheckRefresh);
}
static unsigned long mMainwinLoad( struct IClass *cl, Object *obj, Msg msg )
{
unsigned long _ret = 1;
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
static char buf[512];
static const struct Hook IntuiMsgHook =3D { { 0,0 },(void *)IntuiMsgFunc=
,NULL,NULL };
Object *app =3D (Object *)BCC_XGet( obj, MUIA_ApplicationObject );
set(app,MUIA_Application_Sleep,TRUE);
if (MUI_AslRequestTags((data->objreq),
ASLFR_Window, BCC_XGet( obj, MUIA_Window_Window ),
ASLFR_TitleText, "Load an object",
ASLFR_DoSaveMode, FALSE,
ASLFR_UserData, app,
ASLFR_IntuiMsgFunc, &IntuiMsgHook,
TAG_DONE,0))
{
if (*(data->objreq)->fr_File)
{
stccpy(buf,(data->objreq)->fr_Drawer,sizeof(buf));
AddPart(buf,(data->objreq)->fr_File,sizeof(buf));
LoadModel(buf,(data->Model));
MUI_Redraw((data->viewgr),MADF_DRAWOBJECT);
}
}
set(app,MUIA_Application_Sleep,FALSE);
}
/* UC End */
Load_exit:
return _ret;
}
static char *getfilename(Object *win,char *title,char *dir,char *pattern,=
char save)
{
static char buf[512];
struct FileRequester *req;
struct Window *w;
static long left=3D-1,top=3D-1,width=3D-1,height=3D-1;
Object *app =3D (Object *)BCC_XGet(win,MUIA_ApplicationObject);
char *res =3D NULL;
static const struct Hook IntuiMsgHook =3D { { 0,0 },(VOID *)IntuiMsgFunc=
,NULL,NULL };
get(win,MUIA_Window_Window,&w);
if (left=3D=3D-1)
{
left =3D w->LeftEdge+w->BorderLeft+2;
top =3D w->TopEdge+w->BorderTop+2;
width =3D w->Width-w->BorderLeft-w->BorderRight-4;
height =3D w->Height-w->BorderTop-w->BorderBottom-4;
}
if (req=3DMUI_AllocAslRequestTags(ASL_FileRequest,
ASLFR_Window, w,
ASLFR_TitleText, title,
ASLFR_InitialLeftEdge, left,
ASLFR_InitialTopEdge , top,
ASLFR_InitialWidth , width,
ASLFR_InitialHeight , height,
ASLFR_InitialDrawer , dir,
ASLFR_InitialPattern , pattern,
ASLFR_DoSaveMode , save,
ASLFR_DoPatterns , TRUE,
ASLFR_RejectIcons , TRUE,
ASLFR_UserData , app,
ASLFR_IntuiMsgFunc , &IntuiMsgHook,
TAG_DONE))
{
set(app,MUIA_Application_Sleep,TRUE);
if (MUI_AslRequestTags(req,TAG_DONE))
{
if (*req->fr_File)
{
res =3D buf;
stccpy(buf,req->fr_Drawer,sizeof(buf));
AddPart(buf,req->fr_File,sizeof(buf));
}
left =3D req->fr_LeftEdge;
top =3D req->fr_TopEdge;
width =3D req->fr_Width;
height =3D req->fr_Height;
}
MUI_FreeAslRequest(req);
set(app,MUIA_Application_Sleep,FALSE);
}
return(res);
}
static unsigned long mMainwinZoomIn( struct IClass *cl, Object *obj, Msg msg )
{
unsigned long _ret = 1;
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
BCC_Set( obj, MUIA_Mainwin_Zoom, 3D f2l((data->Zoom) * 1.25) );
}
/* UC End */
ZoomIn_exit:
return _ret;
}
static unsigned long mMainwinZoomOut( struct IClass *cl, Object *obj, Msg msg )
{
unsigned long _ret = 1;
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
BCC_Set( obj, MUIA_Mainwin_Zoom, 3D f2l((data->Zoom) /=A01.25) );
}
/* UC End */
ZoomOut_exit:
return _ret;
}
void aMainwinZoomSet( struct IClass *cl, Object *obj, struct { unsigned long ti_Tag; long zoom ; } *tag )
{
MainwinData *data = INST_DATA( cl, obj );
{
/* UC Beg */
char buf[64];
(data->Zoom) =3D l2f((tag->zoom));
(data->GridSize) =3D pow(10.0,floor(log10(0.1 / (data->Zoom))));
if (fract(log10(1.0 /=A0Zoom)) > 0.699) (data->GridSize) *=3D 5.0;
else if (fract(log10(1.0 /=A0Zoom)) > 0.301) (data->GridSize) *=3D 2.0;
if ((data->GridSize) >=3D 1000000.0)
sprintf(buf,"Grid: %d Mm",(long)((data->GridSize) /=A01000000.0));
else if ((data->GridSize) >=3D 1000.0)
sprintf(buf,"Grid: %d km",(long)((data->GridSize) /=A01000.0));
else if ((data->GridSize) >=3D 1.0)
sprintf(buf,"Grid: %d m",(long)(data->GridSize));
else if ((data->GridSize) >=3D 0.01)
sprintf(buf,"Grid: %d cm",(long)((data->GridSize) * 100.0));
else
sprintf(buf,"Grid: %d mm",(long)((data->GridSize) * 1000.0));
BCC_Set( (data->gridsizetxt), MUIA_Text_Contents, 3D buf );
BCC_Set( (data->viewgr), MUIA_View_Zoom, 3D f2l((data->Zoom)) );
BCC_Set( (data->viewgr), MUIA_View_GridSize, 3D f2l((data->GridSize)) );
MUI_Redraw((data->viewgr),MADF_DRAWOBJECT);
}
/* UC End */
}
/* MUI - Mainwin class dispatcher */
static unsigned long mMainwinOM_SET( struct IClass *cl, Object *obj, struct opSet *msg )
{
struct TagItem *tags, *tag;
for( tags = msg->ops_AttrList; tag = NextTagItem(&tags); ) {
switch( tag->ti_Tag ) {
case MUIA_Mainwin_Zoom: aMainwinZoomSet( cl, obj, (void*)tag ); break;
}
}
return DoSuperMethodA( cl, obj, (Msg)msg );
}
static unsigned long SAVEDS ASM Mainwin_Dispatcher( REG(a0) struct IClass *cl, REG(a2) Object *obj, REG(a1) Msg msg )
{
switch( msg->MethodID ) {
case MUIM_Mainwin_New: return mMainwinNew( cl, obj, (Msg)msg );
case MUIM_Mainwin_Load: return mMainwinLoad( cl, obj, (Msg)msg );
case MUIM_Mainwin_ZoomIn: return mMainwinZoomIn( cl, obj, (Msg)msg );
case MUIM_Mainwin_ZoomOut: return mMainwinZoomOut( cl, obj, (Msg)msg );
case OM_NEW: return mMainwinOM_NEW( cl, obj, (struct opSet*)msg );
case OM_DISPOSE: return mMainwinOM_DISPOSE( cl, obj, (Msg)msg );
case MUIM_HandleEvent: return mMainwinMUIM_HandleEvent( cl, obj, (struct MUIP_HandleEvent*)msg );
case OM_SET: return mMainwinOM_SET( cl, obj, (struct opSet*)msg );
}
return( DoSuperMethodA( cl, obj, msg ) );
}
struct MUI_CustomClass *Mainwin_Create( void )
{
return MUI_CreateCustomClass( NULL, MUIC_Window, NULL, sizeof( MainwinData ), Mainwin_Dispatcher );
}